package com.study01.lesson03_UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

//不需要连接服务器
public class UdpClientDemo01 {
    public static void main(String[] args) throws Exception{
        //1建立一个sockek
        DatagramSocket socket = new DatagramSocket();

        //2建个包
        String msg = "你好，服务器！";
        //发送给谁
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;
        //数据，数据的长度起始，要发给谁
        DatagramPacket packet =  new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,localhost,port);

        //3发送包
        socket.send(packet);

        //4关闭流
        socket.close();
    }
}
